<template>
  <div class="full-screen-container">
    <el-card class="form-card" shadow="hover">
      <h2 class="form-title">账户信息</h2>
      <div class="user-info">
        <p>姓名: {{ userName }}</p>
        <p>账户余额: {{ balance }} 元</p>
      </div>
      <el-form :model="form" ref="formRef" label-width="120px" class="demo-ruleForm">
        <el-form-item label="充值金额" prop="amount">
          <el-input v-model="form.amount" type="number" placeholder="请输入充值金额"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm" class="submit-btn">充值</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';

export default {
  setup() {
    const userName = ref('张三');
    const balance = ref(100.00); // 初始余额

    const form = ref({
      amount: null
    });

    const formRef = ref(null);

    const submitForm = () => {
      // 模拟后端请求和响应
      setTimeout(() => {
        const amount = parseFloat(form.value.amount);
        if (amount > 0) {
          balance.value += amount;
          ElMessage.success('充值成功');
          form.value.amount = null; // 清空输入框
        } else {
          ElMessage.error('请输入有效的充值金额');
        }
      }, 1000);
    };

    return {
      userName,
      balance,
      form,
      formRef,
      submitForm
    };
  }
};
</script>

<style scoped>
.full-screen-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}

.form-card {
  width: 500px;
  padding: 30px;
  border-radius: 10px;
}

.form-title {
  text-align: center;
  margin-bottom: 20px;
  font-size: 24px;
}

.user-info {
  margin-bottom: 20px;
  font-size: 18px;
}

.submit-btn {
  width: 100%;
}
</style>
